/**
 * @author WangChao
 * @version 1.0
 * @date 2023/4/2 11:41
 */
import java.util.*;

public class Main {
    public static void main(String[] args) {
        var grid = new int[]{1, 2};
        smallestSubarrays(grid);
    }
    public static int[] smallestSubarrays(int[] nums) {
        var n = nums.length;
        var ans = new int[n];
        var ors = new ArrayList<int[]>();
        for(int i=n-1;i>=0;i--){
            var num = nums[i];
            ors.add(new int[]{0,i});
            int k = 0;
            for(int []g:ors){
                g[0] |= num;
                if(g[0]==ors.get(k)[0]){
                    ors.get(k)[1] = g[1];
                }else{
                    ors.set(++k,g);
                }
            }
            ors.subList(k+1,ors.size()).clear();
            ans[i] = ors.get(0)[1] - i + 1;
        }
        return ans;
    }
}
